package com.teamwhole.modules.sys.web;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.teamwhole.common.model.ResultInfo;
import com.teamwhole.modules.sys.entity.Role;
import com.teamwhole.modules.sys.service.RoleService;

@Component
@Path("/sys/role")
@Consumes("application/json;charset=utf-8")
@Produces("application/json;charset=utf-8")
public class RoleResource {
	
	@Autowired
	private RoleService roleService;
	
	@Path("/get")
	@GET
	public Role get(@QueryParam("id") String id) {
		return roleService.get(id);
	}
	
	// TODO[待完成] 获取当前用户所能看到的角色列表
	@Path("/list")
	@POST
	public Object list(Role model) {
		return roleService.findAllRole();
	}
	
	@Path("/create")
	@POST
	public ResultInfo create(Role model) {
		roleService.save(model);
		return ResultInfo.ok();
	}
	
	@Path("/update")
	@POST
	public ResultInfo update(Role model) {
		roleService.save(model);
		return ResultInfo.ok();
	}
	
	@Path("/delete")
	@GET
	public ResultInfo delete(@QueryParam("id") String id) {
		roleService.delete(id);
		return ResultInfo.ok();
	}

}
